package Thread;

//静态方法的同步
//当一个静态方法被synchronized修饰后,那么
//该方法即为同步方法,由于静态方法从属类,全局
//就一份,所以同步的静态方法一定具有同步效果.
//与对象无关

public class SynchronizedDemo3 {
    public static void main(String[] args) {
        Foo foo1=new Foo();
        Foo foo2=new Foo();
        Thread thread1=new Thread(){
            @Override
            public void run() {
                foo1.dosome();//与对象无关
            }
        };

        Thread thread2=new Thread(){
            @Override
            public void run() {
                foo2.dosome();
            }
        };
        thread1.start();
        thread2.start();
    }


}

class Foo{
    public synchronized static void dosome(){
        Thread thread=Thread.currentThread();
        System.out.println(thread+"正在执行dosome方法");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(thread+"执行完毕");
    }
}